<?php

namespace App\Models\Conf;

use App\Models\Def\MainGamePlat;
use App\Models\Log\PlayerBetFlow;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Notifications\Notifiable;

use App\Models\Inf\Player;

class Site extends Model
{
    use Notifiable;


    public $table = 'conf_sites';

    const CREATED_AT = 'created_at';

    const UPDATED_AT = 'updated_at';

    public $fillable = [
        'site_name',
        'score',
        'username',
        'password',
        'user_id',
        'agent_id',
        'is_external',
        'status',
        'token'
    ];

    protected $casts = [
        'id' => 'integer',
        'site_name' => 'string',
        'score' => 'numeric',
        'username' => 'string',
        'password' => 'string',
        'is_external' => 'boolean',
        'token' => 'string'
    ];

    public static $rules = [];

    public function Players()
    {
        return $this->hasMany(Player::class, 'site_id', 'id');
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id')->withTrashed();
    }

    public function agent()
    {
        return $this->belongsTo(Agent::class, 'agent_id', 'id');
    }

    public function MainGamePlat()
    {
        return $this->belongsToMany(
            MainGamePlat::class,
            'conf_site_main_game_plats',
            'site_id',
            'main_game_plats_id'
        )
            ->withPivot('rate', 'score')
            ->withTimestamps();
    }

    public function playerBetFlows()
    {
        return $this->hasMany(PlayerBetFlow::class,'site_username','username');
    }


}
